package threadLocal;

import java.util.concurrent.TimeUnit;

/**
 * @author: 李德才
 * @description:
 * @create: 2020-12-13 15:09
 **/
public class ThreadLocal1 {

    /*volatile*/ static Person p = new Person();

    public static void main(String[] args) {

        /**
         * t1 一秒钟之后修修改
         */
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            p.name = "B";
        }, "t1").start();

        /**
         * t2  两秒之后读取
         */
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(p.name);
        }, "t2").start();


    }
    static class Person {
        String name = "A";
    }
}


